﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using spbtzb;
using System.Data.OleDb;

public partial class Content : System.Web.UI.Page
{
    //protected string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='E://spbtzb.mdb';";
    protected string strConnection = spbtzb.ConString.ConnString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //this.Page.Title = "文章内容页面";
            if (Request.Params["articleID"] != null)
            {
                BindArticle(Request.Params["articleID"].ToString());
            }
            else
            {
                //Response.Redirect("Error.aspx");
                Response.Redirect("~/Common/ErrorPage.aspx?ErrorMessage=" + "跳转参数为空，请重新操作或联系管理员!");
            }
        }
    }
    protected void BindArticle(string id)
    {
        string strType = HttpContext.Current.Request.QueryString["TypeCode"].ToString();
        
        OleDbDataReader reader = AccessHelper.ExecuteReader(strConnection, CommandType.Text,
            "Select C.*,CT.ContentType from Contents As C ,ContentAndType As CT where C.ID=CT.ContentID And ContentType= '"+ strType+"' And C.ID=" + id);

        if (reader == null) // add by shiney
        {
            Response.Redirect("~/Common/ErrorPage.aspx?ErrorMessage=" + "操作失败，请重新操作或联系管理员!");
        }
        int visitTimes = 0;
        string typecode = "";
        if (reader.Read())
        {
            ltArticle.Text = Common.ToString(reader["Content"].ToString());
            ltTitle.Text = reader["Title"].ToString();
            this.Page.Title = ltTitle.Text + "页面";
            this.Page.Title = ltTitle.Text;
            if (reader["ViewTimes"] != DBNull.Value)
            {
                visitTimes = Convert.ToInt32(reader["ViewTimes"]);
            }
            else
            {
                visitTimes = 0;
            }
            ltCreateTime.Text = reader["CreateTime"].ToString();
            typecode = reader["ContentType"].ToString();
        }
        else // add by shiney
        {
            div_Content.InnerHtml = "没有您要查看的信息！";
        }

        visitTimes++;
        ltViewTimes.Text = visitTimes.ToString();
        //if (AccessHelper.ExecuteNonQuery(strConnection, CommandType.Text,
        //    "UPDATE Contents SET ViewTimes = " + visitTimes + " WHERE ID = " + id) != 1)
        //{
        //    Response.Redirect("Error.aspx");
        //}

        int iret = AccessHelper.ExecuteNonQuery(strConnection, CommandType.Text,
            "UPDATE Contents SET ViewTimes = " + visitTimes + " WHERE ID = " + id);
        //if (iret <= 0) //for debug by shieny
        //{
        //     Response.Redirect("~/Common/ErrorPage.aspx?ErrorMessage=" + "点击率更新失败!");
        //}
        if (String.IsNullOrEmpty(typecode)) // add by shiney
        {
            return;
        }
        string parentType = Common.GetParentTypeCode(typecode);
        if (string.IsNullOrEmpty(parentType))
        {
            dvNav.InnerHtml += "<a href='ContentList.aspx?type=" + typecode + "'>" + Common.GetTypeNameByCode(typecode) + "</a>";
        }
        else if (parentType != "NOBB")
        {
            dvNav.InnerHtml += "<a href='ContentType.aspx?type=" + parentType + "'>" + Common.GetTypeNameByCode(parentType) + "</a>"
                            + "&nbsp;>>&nbsp;<a href='ContentList.aspx?type=" + typecode + "'>" + Common.GetTypeNameByCode(typecode) + "</a>";
        }
        else 
        {
            dvNav.InnerHtml += "&nbsp;<a href='ContentList.aspx?type=" + typecode + "'>" + Common.GetTypeNameByCode(typecode) + "</a>";
        }
        

    }
}
